package smartcounters.androidclient;

import java.util.ArrayList;

import smartcounters.androidclient.model.AccountInfo;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;

public class FindAccountResultsActivity extends Activity implements OnClickListener{
	public static AccountInfo s_Account;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.find_account_results_layout);
        
        LinearLayout layout = (LinearLayout)findViewById(R.id.findAccountResultsLayout);
        
        ArrayList<AccountInfo> accounts = FindAccountActivity.s_AccountsToShow;
        
        for (int i = 0; i < accounts.size(); i++){
        	AccountInfo account = accounts.get(i);
        	String text = account.getApartment() == -1 ? account.getCountry() + ", " + account.getCity() + ", " + account.getStreet() + ", " + String.valueOf(account.getHouse()) :
        		account.getCountry() + ", " + account.getCity() + ", " + account.getStreet() + ", " + String.valueOf(account.getHouse()) + " / " + String.valueOf(account.getApartment());
        	
        	Button button = new Button(this);
			button.setText(text);
			button.setOnClickListener(this);
			button.setTag(account);
			layout.addView(button); 
        }
    }

	public void onClick(View v) {
		Button button = (Button)v;
		
		s_Account = (AccountInfo)button.getTag();
		
		Intent intent = new Intent();
		intent.setClass(this, AccountDetailsActivity.class);
		startActivity(intent);
	}
}
